package com.dn.luckbi.manager;

import com.dn.luckbi.common.ErrorCode;
import com.dn.luckbi.exception.BusinessException;
import com.yupi.yucongming.dev.client.YuCongMingClient;
import com.yupi.yucongming.dev.common.BaseResponse;
import com.yupi.yucongming.dev.model.DevChatRequest;
import com.yupi.yucongming.dev.model.DevChatResponse;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 染染熊
 * @version 1.0
 * @date 2024/3/26 9:36
 */

@Service
public class AiManager {

    @Resource
    private YuCongMingClient client;

    /**
     * Ai对话
     * @param modelId
     * @param message
     */
    public String doChat(long modelId, String message) {
        DevChatRequest devChatRequest = new DevChatRequest();
        devChatRequest.setModelId(modelId);
        devChatRequest.setMessage(message);
        BaseResponse<DevChatResponse> response = client.doChat(devChatRequest);
        if (response == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "AI调用失败");
        }
        return response.getData().toString();
    }

}
